package com.ruoyi.web.controller.fund;

import com.ruoyi.area.domain.HouseAreaT;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.cost.domain.FundCostT;
import com.ruoyi.costQuery.domain.HouseCostT;
import com.ruoyi.data.MD5;
import com.ruoyi.doorBind.domain.DoorBindT;
import com.ruoyi.doorBind.service.IDoorBindTService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * 户管理Controller
 * 
 * @author lijie
 * @date 2023-04-20
 */
@RestController
@RequestMapping("/fund/doorBind")
public class DoorBindTController extends BaseController
{
    @Autowired
    private IDoorBindTService doorBindTService;

    /**
     * 查询户管理列表
     */
   @GetMapping("/leftList")
    public TableDataInfo leftList(DoorBindT doorBindT) throws Exception {
        startPage();
        List<DoorBindT> list = new ArrayList<DoorBindT>();
        if(!("".equals(doorBindT.getAreaName())|| doorBindT.getAreaName()==null)){
            if(!("".equals(doorBindT.getUserName())|| doorBindT.getUserName()==null)){
                doorBindT.setUserName(MD5.encrypt(doorBindT.getUserName()));
            }
            list = doorBindTService.selectLeftList(doorBindT);
            for(DoorBindT doorBindVO : list) {
                doorBindVO.setUserName(MD5.decrypt(doorBindVO.getUserName()));
                doorBindVO.setTel(MD5.decrypt(doorBindVO.getTel()));
            }
        }

        return getDataTable(list);
    }

    /**
     * 查询户管理列表
     */
    @GetMapping("/rightList")
    public TableDataInfo rightList(DoorBindT doorBindT) throws Exception {
        startPage();
        List<DoorBindT> list = new ArrayList<DoorBindT>();
        if(!("".equals(doorBindT.getAreaName())|| doorBindT.getAreaName()==null)){
            list = doorBindTService.selectRightList(doorBindT);
        }
        for (DoorBindT doorBindVO : list) {
            doorBindVO.setUserName(MD5.decrypt(doorBindVO.getUserName()));
            doorBindVO.setTel(MD5.decrypt(doorBindVO.getTel()));
        }
        return getDataTable(list);
    }

    @Log(title = "绑定管理", businessType = BusinessType.UPDATE)
    @PutMapping("/updateBind")
    public AjaxResult updateBind(@RequestBody DoorBindT doorBindT) throws Exception {
        doorBindT.setCreater(getUsername());
        if(doorBindT.getPapersCode()!=null){
            doorBindT.setPapersCode(MD5.encrypt(doorBindT.getPapersCode()));
            doorBindT.setUserName(MD5.encrypt(doorBindT.getUserName()));
            doorBindT.setTel(MD5.encrypt(doorBindT.getTel()));
        }
        doorBindTService.updateDoorBindT(doorBindT);
        return AjaxResult.success(1);
    }

    @Log(title = "添加户信息", businessType = BusinessType.INSERT)
    @PostMapping("/insertDoor")
    public AjaxResult insertDoor(@RequestBody DoorBindT doorBindT) throws Exception {
        List<DoorBindT> list = new ArrayList<DoorBindT>();
        if(!("".equals(doorBindT.getAreaName())|| doorBindT.getAreaName()==null)){
            list = doorBindTService.selectLeftList(doorBindT);
        }
        for (DoorBindT doorBindVO : list) {
            doorBindVO.setUserName(MD5.encrypt(doorBindVO.getUserName()));
            doorBindVO.setTel(MD5.encrypt(doorBindVO.getTel()));
            doorBindVO.setCreater(getUsername());
            doorBindTService.insertDoor(doorBindVO);
        }
        return toAjax(1);
    }


}
